import { publicMsg } from "./publicMsg.js"

export function RouterTo(_this,path,querys,name) {
	if(!!path&&!querys){
		_this.$router.push({"path":path})
	}else if(!!name){
		_this.$router.push({"name":path})
	}else if(!!querys&&!!path){
		_this.$router.push({"path":path,"query":querys});
	}else if(!!querys&&!!name){
		_this.$router.push({"name":path,"query":querys});
	}
}


export function getQueryStringArgs() {
		var str = window.location.href.split("?")[1]
		if(str){
			var qs = (location.search.length>0 ? location.search.substring(1) : str.substring(0,str.length));
		}else{
			var qs = '';
		}
		var args = {};
		var items = qs.length?qs.split("&"):[];
		var item = null;
		var name = null;
		var value = null;
		var len = items.length;
		for(var i = 0;i<len;i++){
			item = items[i].split("=");
			name = decodeURIComponent(item[0]);
		    value = decodeURIComponent(item[1]);
		    
		    if(name.length){
		    	args[name] = value;
		    }
		}
		return args;
	}


//深拷贝

export function cloneObj (obj) {
  var newObj = {}
  for(var prop in obj) {
    newObj[prop] = obj[prop]
  }
  return newObj
}

//获取当前url主机
export function getUrlHost (){
	if(window.location.hostname == "localhost" || window.location.hostname == "127.0.0.1"){
		return "http://192.168.0.82:7091"
	}else{
		if(!window.location.port){
	  		return window.location.protocol+"//"+window.location.hostname;
	  	}else{
	  		return window.location.protocol+"//"+window.location.hostname+":"+window.location.port;
	  	}
	}
}
